using System;
using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Alterations;
using MvcMall.Core.Domains;
using MvcMall.Core.Enums;

namespace MvcMall.Data.NHibernateMaps
{
    public class UserMap : IAutoMappingOverride<User>
    {
        public void Override(AutoMapping<User> mapping)
        {
            mapping.Map(c => c.UserName).Unique().Equals(true);
            mapping.Map(c => c.Sex).CustomType(typeof(Sex));
            mapping.HasMany(c => c.UserAddresses);
            mapping.HasOne(c => c.UserAccount).Cascade.All().LazyLoad();
            mapping.HasOne(c => c.Store).Cascade.All().LazyLoad();
            mapping.HasMany(c => c.SendAccountTrans).KeyColumn("SendUser");
            mapping.HasMany(c => c.ReceiveAccountTrans).KeyColumn("ReceiveUser");
            mapping.HasMany(c => c.UserUploadLogs);
            mapping.HasMany(m => m.UserFindPwdLogs);
            mapping.HasMany(m => m.UserLoginLogs);
            mapping.HasMany(m => m.SendMessages).KeyColumn("SendUser");
            mapping.HasMany(m => m.ReceiveMessages).KeyColumn("ReceiveUser");
            mapping.HasMany(m => m.PromoteStores).KeyColumn("PromoteUser");
            mapping.HasMany(m => m.SysMessages).KeyColumn("ReceiveUser");
            mapping.HasMany(m => m.StoreApplies);
            mapping.HasMany(c => c.GoodsFavorites);
            mapping.HasMany(c => c.StoreFavorites);
        }
    }
}